function AllReady() {
    var mstform = Ext.getCmp('tenderprojectMst_form');
    var dgrid = Ext.getCmp('tenderprojectEdit_grid');
    var dstore=dgrid.store;
  
  
   var record;
   dstore.on('datachanged', function (store, eOpts) {
         var gyslx=mstform.getItem('user_gyslx').getValue();
         if(gyslx=='1580' || gyslx=='1582'){
               for (var i=0; i<dstore.getCount(); i++) {
                 record = dstore.getAt(i);//将所有数据循环遍历
                 record.set('TendCycle',1);
               }
               dgrid.setReadOnlyCol('TendCycle',true);    
         }else{
               dgrid.setReadOnlyCol('TendCycle',false);  
         }
   });   
  
  dgrid.store.on('add', function(store, records, index, eOpts){
      var gyslx=mstform.getItem('user_gyslx').getValue();
      if(gyslx=='1580' || gyslx=='1582'){
            for(var i=0; i<records.length; i++){//将所有数据循环遍历
                   records[i].set('TendCycle',1);
            }
           dgrid.setReadOnlyCol('TendCycle',true);    
      }else{
          dgrid.setReadOnlyCol('TendCycle',false);  
      }
 });  
  
  
    if (otype == $Otype.ADD) {
        execServer('getUserDept', {
            userid: $appinfo.userID
        }, function (res) {
            if (res && res.data.length > 0) {
                mstform.getItem('ContactPhone').setValue(res.data[0].mobileno);
                mstform.getItem('PhidDepartment').setValue(res.data[0].deptid);
                BatchBindCombox([mstform.getItem('PhidDepartment')]);
            }
        });
    }
    mstform.getItem('user_lsjl').setValue('0');
    var scheme = mstform.getItem('PhidSchemeid').getValue();
    /*if( scheme !='100221119000001'){
        mstform.getItem('PhidTenderType').userSetMustInput(true);
    }else{
        mstform.getItem('PhidTenderType').userSetMustInput(false);   
    }*/
    mstform.getItem('PhidTenderType').addListener('beforetriggerclick', function () {
        var zygllx= mstform.getItem ('user_gyslx').getValue();
        if(zygllx){
             //根据固定字段进行过滤
             if(zygllx == '100230329021003'){
                  this.setClientSqlFilter("c_no like 'F%'");
             }else{
                  //this.setOutFilter({pid:zygllx});  
                  this.setClientSqlFilter("phid in (select phid from fg_simple_data where c_type = 'tender_type' and (cancel_flg is null or cancel_flg=0) and pid ='"+zygllx+"')");
             }
       }else{
           Ext.Msg.alert('提示','专业管理类型不能为空！');
           return false;
       }
    });
  
  
    mstform.getItem('user_gyslx').addListener('helpselected', function (res) {
        mstform.getItem('user_zbsx').setOutFilter({
            user_gyslx: res.code
        });
        var lx = mstform.getItem('user_gyslx').getValue(); //
        if (lx != '-1' && lx != '3' || lx != '1577' && lx != '1581') {
            mstform.getItem('user_jzbh').setValue(964200616000076); //集招项目
            BatchBindCombox([mstform.getItem('user_jzbh')]); //代码转名称
        } else if (lx == -1 || lx == 3 || lx == '1577' && lx == '1581') {
            mstform.getItem('user_jzbh').setValue(''); //集招项目

        }
    });
    BatchBindCombox([mstform.getItem('user_gyslx')]);


    mstform.getItem('PhidTenderMethod').addListener('helpselected', function (res) {
        if (res.code == '1289' || res.code == '1290' || res.code == '1293') {
            mstform.getItem('user_kgfs').setValue('1');
        } else {
            mstform.getItem('user_kgfs').setValue('2');
        }

    });
if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.VIEW) {
          var scheme = mstform.getItem('PhidSchemeid').getValue();
        		if (scheme == '100221119001002') { //引采购计划
                    mstform.getItem('user_zyfbjh').setVisible(false);
                    mstform.getItem('user_fwjh').setVisible(false);
                    //mstform.getItem('user_cgzzms').setVisible(false);
                    mstform.getItem('user_zbsx').setVisible(true);
                    mstform.getItem('user_kjxyjh').setVisible(false); 
                    mstform.getItem('user_gzbg').setVisible(false);
            	} else if (scheme == '100221119002002') { //引专业分包计划
                    mstform.getItem('user_zbsx').setVisible(false);
                    mstform.getItem('user_fwjh').setVisible(false);
                    //mstform.getItem('user_cgzzms').setVisible(false);
                    mstform.getItem('user_zyfbjh').setVisible(true);
                    mstform.getItem('user_zbbh').userSetMustInput(false);
                    mstform.getItem('user_kjxyjh').setVisible(false);   
                    mstform.getItem('user_gzbg').setVisible(false);
            	} else if (scheme == '' || scheme == '100221119000001' || scheme == '964200426002005') { //直接新增
                    mstform.getItem('user_zbsx').setVisible(false);
                    mstform.getItem('user_zyfbjh').setVisible(false);
                    mstform.getItem('user_cgkzj').userSetReadOnly(false);
                    mstform.getItem('user_fwjh').setVisible(false);
                    //mstform.getItem('user_cgzzms').setVisible(false);
                    mstform.getItem('user_kjxyjh').setVisible(false);   
                    mstform.getItem('user_gzbg').setVisible(false);
            	}else if(scheme == '100230414065503'){//引服务请购单
                    mstform.getItem('user_zbsx').setVisible(false);
                    mstform.getItem('user_zyfbjh').setVisible(false);
                    mstform.getItem('user_fwjh').setVisible(true);
                    mstform.getItem('user_fwywlx').userSetReadOnly(true);
                    mstform.getItem('user_kjxyjh').setVisible(false);   
                    mstform.getItem('user_gzbg').setVisible(false);
            	}else if(scheme=='100230414088003'){//引购置报告
                    mstform.getItem('user_zbsx').setVisible(false);
                    mstform.getItem('user_zyfbjh').setVisible(false);
                    mstform.getItem('user_fwjh').setVisible(false);   
                    mstform.getItem('user_gzbg').setVisible(true);
                    mstform.getItem('user_ywlx_zic').userSetReadOnly(true);   
                    mstform.getItem('user_kjxyjh').setVisible(false);     
                }else if(scheme=='100230414096502'){//框架协议
                    mstform.getItem('user_zbsx').setVisible(false);
                    mstform.getItem('user_zyfbjh').setVisible(false);
                    mstform.getItem('user_fwjh').setVisible(false);   
                    mstform.getItem('user_gzbg').setVisible(false);
                    mstform.getItem('user_kjxyjh').setVisible(true);                                           
                }else if(scheme=='395000000000174' || scheme=='395000000000197'){//劳务分包
                    mstform.getItem('user_zbsx').setVisible(false);
                    mstform.getItem('user_zyfbjh').setVisible(false);
                    mstform.getItem('user_fwjh').setVisible(false);   
                    mstform.getItem('user_gzbg').setVisible(false);
                    mstform.getItem('user_kjxyjh').setVisible(false);
                    mstform.getItem('user_lwcgsq').setVisible(true);
                    mstform.getItem('ProjectAddr').userSetMustInput(true);

                }
  
  
                  if( scheme=='395000000000174'){//工程队
                   mstform.getItem('user_cgbhskzj').userSetMustInput(true);
                   mstform.getItem('user_cgbhskzj').setVisible(true);
                }else{
                   mstform.getItem('user_cgbhskzj').setVisible(false);
                   mstform.getItem('user_cgbhskzj').userSetMustInput(false);  
                }
  
                if(scheme != '395000000000197' && scheme != '395000000000174'){//不等于劳务分包
                   mstform.getItem('user_cgkzj').userSetMustInput(true);
                   mstform.getItem('user_cgkzj').setVisible(true);
                }else{

                   mstform.getItem('user_cgkzj').userSetMustInput(false);  
                   mstform.getItem('user_cgkzj').setVisible(false);
                }
  
                if( scheme=='395000000000197'){//劳务企业
                   dgrid.setMustInputCol('user_glfbl',true);
                   dgrid.setMustInputCol('user_slbl',true);
                   dgrid.hideColumn('user_glfbl',false);
                   dgrid.hideColumn('user_slbl',false);
                  
                   mstform.getItem('user_glfbl').userSetMustInput(true);
                   mstform.getItem('user_glfbl').setVisible(true);
                }else{
                   dgrid.setMustInputCol('user_glfbl',false);
                   dgrid.setMustInputCol('user_slbl',false);
                   dgrid.hideColumn('user_glfbl',true);
                   dgrid.hideColumn('user_slbl',true);   
                  
                   mstform.getItem('user_glfbl').userSetMustInput(false);
                   mstform.getItem('user_glfbl').setVisible(false);
                }
                if(scheme=='100230414096502'){//框架协议
                    mstform.getItem('user_kjyxq').setVisible(true);   
                    mstform.getItem('user_kjjzq').setVisible(true);
                    mstform.getItem('user_ywlx_kj').setVisible(true);     
                    mstform.getItem('ProjectAddr').setVisible(false);   
                  
                    mstform.getItem('user_fgxm').setVisible(true);   
                    mstform.getItem('user_fgzz').setVisible(true);
                    mstform.getItem('user_fgdy').setVisible(true); 
                    mstform.getItem('user_bjfs').setVisible(true);
                    //mstform.getItem('user_kjygje').setVisible(true); 
                   
                    dgrid.hideColumn('user_kjxygz',false); 
                    dgrid.hideColumn('user_kjhskzj',false); 
                    dgrid.hideColumn('user_kjcjgz',false); 
                  
                    mstform.getItem('user_jhjgrq').setVisible(false);
                    mstform.getItem('user_sjjgrq').setVisible(false); 
                    mstform.getItem('user_qzjgrq').setVisible(false);
                }else{
                    mstform.getItem('user_ywlx_kj').setVisible(false);
                    mstform.getItem('user_kjyxq').setVisible(false);
                    mstform.getItem('user_kjjzq').setVisible(false);   
                    mstform.getItem('ProjectAddr').setVisible(true);
                  
                    mstform.getItem('user_fgxm').setVisible(false);   
                    mstform.getItem('user_fgzz').setVisible(false);
                    mstform.getItem('user_fgdy').setVisible(false); 
                    mstform.getItem('user_bjfs').setVisible(false);
                    //mstform.getItem('user_kjygje').setVisible(false); 
                  
                    dgrid.hideColumn('user_kjxygz',true); 
                    dgrid.hideColumn('user_kjhskzj',true); 
                    dgrid.hideColumn('user_kjcjgz',true);
                  
                    mstform.getItem('user_jhjgrq').setVisible(true);
                    mstform.getItem('user_sjjgrq').setVisible(true); 
                    mstform.getItem('user_qzjgrq').setVisible(true);
                }
  
    }
//数据加载完成后触发 
mstform.on('dataready',function(){
    if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.VIEW) {
          var scheme = mstform.getItem('PhidSchemeid').getValue();
        		if (scheme == '100221119001002') { //引采购计划
                    mstform.getItem('user_zyfbjh').setVisible(false);
                    mstform.getItem('user_fwjh').setVisible(false);
                    //mstform.getItem('user_cgzzms').setVisible(false);
                    mstform.getItem('user_zbsx').setVisible(true);
                    mstform.getItem('user_kjxyjh').setVisible(false); 
                    mstform.getItem('user_gzbg').setVisible(false);
            	} else if (scheme == '100221119002002') { //引专业分包计划
                    mstform.getItem('user_zbsx').setVisible(false);
                    mstform.getItem('user_fwjh').setVisible(false);
                    //mstform.getItem('user_cgzzms').setVisible(false);
                    mstform.getItem('user_zyfbjh').setVisible(true);
                    mstform.getItem('user_zbbh').userSetMustInput(false);
                    mstform.getItem('user_kjxyjh').setVisible(false);   
                    mstform.getItem('user_gzbg').setVisible(false);
            	} else if (scheme == '' || scheme == '100221119000001' || scheme == '964200426002005') { //直接新增
                    mstform.getItem('user_zbsx').setVisible(false);
                    mstform.getItem('user_zyfbjh').setVisible(false);
                    mstform.getItem('user_cgkzj').userSetReadOnly(false);
                    mstform.getItem('user_fwjh').setVisible(false);
                    //mstform.getItem('user_cgzzms').setVisible(false);
                    mstform.getItem('user_kjxyjh').setVisible(false);   
                    mstform.getItem('user_gzbg').setVisible(false);
            	}else if(scheme == '100230414065503'){//引服务请购单
                    mstform.getItem('user_zbsx').setVisible(false);
                    mstform.getItem('user_zyfbjh').setVisible(false);
                    mstform.getItem('user_fwjh').setVisible(true);
                    mstform.getItem('user_fwywlx').userSetReadOnly(true);
                    mstform.getItem('user_kjxyjh').setVisible(false);   
                    mstform.getItem('user_gzbg').setVisible(false);
            	}else if(scheme=='100230414088003'){//引购置报告
                    mstform.getItem('user_zbsx').setVisible(false);
                    mstform.getItem('user_zyfbjh').setVisible(false);
                    mstform.getItem('user_fwjh').setVisible(false);   
                    mstform.getItem('user_gzbg').setVisible(true);
                    mstform.getItem('user_ywlx_zic').userSetReadOnly(true);   
                    mstform.getItem('user_kjxyjh').setVisible(false);     
                }else if(scheme=='100230414096502'){//框架协议
                    mstform.getItem('user_zbsx').setVisible(false);
                    mstform.getItem('user_zyfbjh').setVisible(false);
                    mstform.getItem('user_fwjh').setVisible(false);   
                    mstform.getItem('user_gzbg').setVisible(false);
                    mstform.getItem('user_kjxyjh').setVisible(true);                                           
                }else if(scheme=='395000000000174' || scheme=='395000000000197'){//劳务分包
                    mstform.getItem('user_zbsx').setVisible(false);
                    mstform.getItem('user_zyfbjh').setVisible(false);
                    mstform.getItem('user_fwjh').setVisible(false);   
                    mstform.getItem('user_gzbg').setVisible(false);
                    mstform.getItem('user_kjxyjh').setVisible(false);
                    mstform.getItem('user_lwcgsq').setVisible(true);
                    mstform.getItem('ProjectAddr').userSetMustInput(true);
                }
  
                  if( scheme=='395000000000174'){//工程队
                   mstform.getItem('user_cgbhskzj').userSetMustInput(true);
                   mstform.getItem('user_cgbhskzj').setVisible(true);
                }else{
                   mstform.getItem('user_cgbhskzj').setVisible(false);
                   mstform.getItem('user_cgbhskzj').userSetMustInput(false);  
                }
  
                if(scheme != '395000000000197' && scheme != '395000000000174'){//不等于劳务分包
                   mstform.getItem('user_cgkzj').userSetMustInput(true);
                   mstform.getItem('user_cgkzj').setVisible(true);
                }else{

                   mstform.getItem('user_cgkzj').userSetMustInput(false);  
                   mstform.getItem('user_cgkzj').setVisible(false);
                }
  
                if( scheme=='395000000000197'){//劳务企业
                   dgrid.setMustInputCol('user_glfbl',true);
                   dgrid.setMustInputCol('user_slbl',true);
                   dgrid.hideColumn('user_glfbl',false);
                   dgrid.hideColumn('user_slbl',false);
                  
                   mstform.getItem('user_glfbl').userSetMustInput(true);
                   mstform.getItem('user_glfbl').setVisible(true);
                }else{
                   dgrid.setMustInputCol('user_glfbl',false);
                   dgrid.setMustInputCol('user_slbl',false);
                   dgrid.hideColumn('user_glfbl',true);
                   dgrid.hideColumn('user_slbl',true);   
                  
                   mstform.getItem('user_glfbl').userSetMustInput(false);
                   mstform.getItem('user_glfbl').setVisible(false);
                }
      
                if(scheme=='100230414096502'){//框架协议
                    mstform.getItem('user_kjyxq').setVisible(true);   
                    mstform.getItem('user_kjjzq').setVisible(true);
                    mstform.getItem('user_ywlx_kj').setVisible(true);     
                    mstform.getItem('ProjectAddr').setVisible(false);   
                  
                    mstform.getItem('user_fgxm').setVisible(true);   
                    mstform.getItem('user_fgzz').setVisible(true);
                    mstform.getItem('user_fgdy').setVisible(true); 
                    mstform.getItem('user_bjfs').setVisible(true);
                    //mstform.getItem('user_kjygje').setVisible(true); 
                   
                    dgrid.hideColumn('user_kjxygz',false); 
                    dgrid.hideColumn('user_kjhskzj',false); 
                    dgrid.hideColumn('user_kjcjgz',false); 
                  
                    mstform.getItem('user_jhjgrq').setVisible(false);
                    mstform.getItem('user_sjjgrq').setVisible(false); 
                    mstform.getItem('user_qzjgrq').setVisible(false);
                }else{
                    mstform.getItem('user_ywlx_kj').setVisible(false);
                    mstform.getItem('user_kjyxq').setVisible(false);
                    mstform.getItem('user_kjjzq').setVisible(false);   
                    mstform.getItem('ProjectAddr').setVisible(true);
                  
                    mstform.getItem('user_fgxm').setVisible(false);   
                    mstform.getItem('user_fgzz').setVisible(false);
                    mstform.getItem('user_fgdy').setVisible(false); 
                    mstform.getItem('user_bjfs').setVisible(false);
                    //mstform.getItem('user_kjygje').setVisible(false); 
                  
                    dgrid.hideColumn('user_kjxygz',true); 
                    dgrid.hideColumn('user_kjhskzj',true); 
                    dgrid.hideColumn('user_kjcjgz',true);
                  
                    mstform.getItem('user_jhjgrq').setVisible(true);
                    mstform.getItem('user_sjjgrq').setVisible(true); 
                    mstform.getItem('user_qzjgrq').setVisible(true);
                }
      
    }
  
})
  
   mstform.getItem ('user_lwcgsq').on('helpselected', function (res) {
          mstform.getItem('user_zbbh').setValue(res.data.u_cgbm);
          mstform.getItem('user_cgfs').setValue(res.data.u_cgfs1);
          execServer('getlwsqb', {phid: res.code}, function (res1) {
                if (res1.data && res1.data.length > 0) {
                      mstform.getItem('user_zbxm').setValue(res1.data[0].pc);
                      mstform.getItem('ProjectAddr').setValue(res1.data[0].xmdz);
                      mstform.getItem('user_jhjgrq').setValue(res1.data[0].jgrq);
                      mstform.getItem('user_sjjgrq').setValue(res1.data[0].jgrq);
                      mstform.getItem('user_cgzzms').setValue(res1.data[0].cgzzms);
                      mstform.getItem('PhidTenderMethod').setValue(res1.data[0].xyfs);
          			  var scheme1 = mstform.getItem('PhidSchemeid').getValue();
                      //if(scheme1=='395000000000174' ){//工程队
                      	mstform.getItem('user_cgbhskzj').setValue(res1.data[0].amt);
                        mstform.getItem('user_cgkzj').setValue(res1.data[0].zkgj);
                     // }else if(scheme1=='395000000000197'){//劳务企业
                      	mstform.getItem('user_glfbl').setValue(res1.data[0].glfbl);
                      //}
                }
           });
         BatchBindCombox([mstform.getItem('user_cgfs'),mstform.getItem('user_zbxm'),mstform.getItem('PhidTenderMethod')]);
  });

  mstform.getItem('user_bjfs').addListener('change', function (e, val, oldVal) {
               if(val =='02'){//固定价
                 dgrid.hideColumn('user_kjhskzj',true); 
                 dgrid.hideColumn('user_wlms',true); 
                 dgrid.setMustInputCol('ListCode',true); 
                 dgrid.setMustInputCol('ListName',true); 
           }else{
                 dgrid.hideColumn('user_kjhskzj',false); 
                 dgrid.hideColumn('user_wlms',false); 
                 dgrid.setMustInputCol('ListCode',false); 
                 dgrid.setMustInputCol('ListName',false); 
           }
         	

   })
  
    var controlGridZlzqColumn = function (user_gyslx) {
        if (user_gyslx == '2' || user_gyslx == '4' || user_gyslx == '1580' || user_gyslx == '1582') {
            dgrid.hideColumn('user_zlzq', false);
        } else {
            dgrid.hideColumn('user_zlzq', true);
        }
    }

    var controlGridJjgzColumn = function (cgfs) {
        if (cgfs == '100210713000006') {
            dgrid.hideColumn('user_jjgz', false);
        } else {
            dgrid.hideColumn('user_jjgz', true);
        }
    }

    var controlFormYwlx = function (zygllx) {
        var scheme = mstform.getItem('PhidSchemeid').getValue();
        if(scheme !='100230414096502'){//框架协议
       /* if (zygllx == '1578') {
            mstform.getItem('user_ywlx_cl').setVisible(true);
            mstform.getItem('user_ywlx_zy').setVisible(false);
            mstform.getItem('user_ywlx_sb').setVisible(false);
            mstform.getItem('user_fwywlx').setVisible(false);
            mstform.getItem('user_ywlx_zc').setVisible(false);
            mstform.getItem('user_ywlx_sz').setVisible(false);
            mstform.getItem('user_ywlx_zic').setVisible(false);
        } else if (zygllx == '1580') {
            mstform.getItem('user_ywlx_sb').setVisible(true);
            mstform.getItem('user_ywlx_zy').setVisible(false);
            mstform.getItem('user_ywlx_cl').setVisible(false);
            mstform.getItem('user_fwywlx').setVisible(false);
            mstform.getItem('user_ywlx_zc').setVisible(false);
            mstform.getItem('user_ywlx_sz').setVisible(false);
            mstform.getItem('user_ywlx_zic').setVisible(false);
        }else if(zygllx == '1582'){
             mstform.getItem('user_ywlx_sb').setVisible(false);
            mstform.getItem('user_ywlx_zy').setVisible(false);
            mstform.getItem('user_ywlx_cl').setVisible(false);
            mstform.getItem('user_fwywlx').setVisible(false);
            mstform.getItem('user_ywlx_zc').setVisible(true);
            mstform.getItem('user_ywlx_sz').setVisible(false); 
            mstform.getItem('user_ywlx_zic').setVisible(false);
        }else if(zygllx == '100230329021002'){
            mstform.getItem('user_ywlx_sb').setVisible(false);
            mstform.getItem('user_ywlx_zy').setVisible(false);
            mstform.getItem('user_ywlx_cl').setVisible(false);
            mstform.getItem('user_fwywlx').setVisible(false);
            mstform.getItem('user_ywlx_zc').setVisible(false);
            mstform.getItem('user_ywlx_sz').setVisible(true);
            mstform.getItem('user_ywlx_zic').setVisible(false);
        }else if ( zygllx == '1579') {//专业分包
            mstform.getItem('user_ywlx_zy').setVisible(true);
            //mstform.getItem('user_ywlx_cl').setVisible(false);
            //mstform.getItem('user_ywlx_sb').setVisible(false);
            mstform.getItem('user_fwywlx').setVisible(false);
            //mstform.getItem('user_ywlx_zc').setVisible(false);
            //mstform.getItem('user_ywlx_sz').setVisible(false);
            mstform.getItem('user_ywlx_zic').setVisible(false);
        }
        */
          
          if (zygllx == '100230329021003'){//服务
            //mstform.getItem('user_ywlx_sb').setVisible(false);
            mstform.getItem('user_ywlx_zy').setVisible(false);
            //mstform.getItem('user_ywlx_cl').setVisible(false);
            mstform.getItem('user_fwywlx').setVisible(true);
            //mstform.getItem('user_ywlx_zc').setVisible(false);
            //mstform.getItem('user_ywlx_sz').setVisible(false);
            mstform.getItem('user_ywlx_zic').setVisible(false);
        }else if(zygllx== '100230329022002'){//资产
            //mstform.getItem('user_ywlx_zc').setVisible(false);
            //mstform.getItem('user_ywlx_sz').setVisible(false);
            //mstform.getItem('user_ywlx_sb').setVisible(false);
            mstform.getItem('user_ywlx_zy').setVisible(false);
            //mstform.getItem('user_ywlx_cl').setVisible(false);
            mstform.getItem('user_fwywlx').setVisible(false);
            mstform.getItem('user_ywlx_zic').setVisible(true);
        }else{
            //mstform.getItem('user_ywlx_zc').setVisible(false);
            //mstform.getItem('user_ywlx_sz').setVisible(false);
            //mstform.getItem('user_ywlx_sb').setVisible(false);
            mstform.getItem('user_ywlx_zy').setVisible(false);
            //mstform.getItem('user_ywlx_cl').setVisible(false);
            mstform.getItem('user_fwywlx').setVisible(false);
            mstform.getItem('user_ywlx_zic').setVisible(false);
        }
      }else{
            //mstform.getItem('user_ywlx_cl').setVisible(false);
            mstform.getItem('user_ywlx_zy').setVisible(false);
            //mstform.getItem('user_ywlx_sb').setVisible(false);
            mstform.getItem('user_fwywlx').setVisible(false);
            //mstform.getItem('user_ywlx_zc').setVisible(false);
            //mstform.getItem('user_ywlx_sz').setVisible(false);
            mstform.getItem('user_ywlx_zic').setVisible(false);
      } 
        
    }

    controlFormYwlx();

    mstform.getItem('user_gyslx').addListener('change', function (e, val, oldVal) {
        //controlGridZlzqColumn(val);
       controlFormYwlx(val);
    })

    mstform.getItem('user_cgfs').addListener('helpselected', function (res) {
        controlGridJjgzColumn(res.code);
    });

    /*mstform.getItem('user_zbsx').addListener('beforetriggerclick', function (res) {
        var type = mstform.getItem('user_gyslx').getValue();
        if (type) {
            Ext.Msg.alert('提示', '请先选择专业管理类型');
            return false;
        }
    });*/


  
    var projectAddr = '';

    mstform.getItem('PhidPc').addListener('helpselected', function (res) {
       var scheme = mstform.getItem('PhidSchemeid').getValue();
      if(scheme == '100221119000001'){
           var pc=mstform.getItem('PhidPc').getValue();
           execServer('getpcdz', {phid: pc}, function (res) {
                if (res.data && res.data.length > 0) {
                      var dz=res.data[0].sf+res.data[0].cs+res.data[0].qx;//+res.data.ProjectAddress
                      mstform.getItem('ProjectAddr').setValue(dz);
                      projectAddr=dz;
                }
           });

      }
        if (projectAddr) {
            mstform.getItem('ProjectAddr').setValue(projectAddr);
        }
       var phid =res.code;
       execServer('getpcNews',{phid:phid},function(res1){
        if(res1&& res1.data.length>0){
          mstform.getItem('user_jhjgrq').setValue(res1.data[0].end_date);
          mstform.getItem('user_sjjgrq').setValue(res1.data[0].fact_end_dt);
          mstform.getItem('user_qzjgrq').setValue(res1.data[0].user_qzrq);            
        }
      });
  });
  
//标的物  
function a1(phid) {
    if(phid !=''  && phid !=null){
          execServer('getywlxbdw',{'phid':phid}, function (res) {     
              if(res.data && res.data.length > 0){
                var name=res.data[0].name;
                mstform.getItem('user_bdwmc').setValue(name);   
              }      
            });
    }
}
  
  mstform.getItem ('user_kjxyjh').on('beforetriggerclick', function (eOp, ignoreBeforeEvent) {
       this.setClientSqlFilter('u_cgfs in (select phid from cg_mode  where phid in(964190416000006,100230105000003))')
  });

//框架协议
 mstform.getItem ('user_kjxyjh').on('helpselected', function (res) {
           var a=res.data.phid;
           execServer('getacxx', {phid: a}, function (resa) {
                if (resa.data && resa.data.length > 0) {
                      mstform.getItem('user_isac').setValue(resa.data[0].isac);
                }
           });
   
           mstform.getItem('PhidTenderType').setValue(res.data.u_zygllx);
           mstform.getItem('user_zbbh').setValue(res.data.bill_no);
           mstform.getItem('ProjectName').setValue(res.data.title);
           mstform.getItem('user_cgzzms').setValue(res.data.u_cgzzms);
           mstform.getItem('user_cgfs').setValue(res.data.u_cgfs);
           mstform.getItem('user_ywlx_kj').setValue(res.data.u_cgpl);
           mstform.getItem('PhidTenderMethod').setValue(res.data.u_xyfs);
           if(res.data.u_bjfs =='02'){//固定价
                 dgrid.hideColumn('user_kjhskzj',true); 
                 dgrid.hideColumn('user_wlms',true); 
                 dgrid.setMustInputCol('ListCode',true); 
                 dgrid.setMustInputCol('ListName',true); 
           }else{
                 dgrid.hideColumn('user_kjhskzj',false); 
                 dgrid.hideColumn('user_wlms',false); 
                 dgrid.setMustInputCol('ListCode',false); 
                 dgrid.setMustInputCol('ListName',false); 
           }
         	
           mstform.getItem('user_cgkzj').setValue(res.data.u_hskzj);
           mstform.getItem('user_kjyxq').setValue(res.data.u_kjyyq);
           mstform.getItem('user_kjjzq').setValue(res.data.u_kjjzrq);
           mstform.getItem('user_fgxm').setValue(res.data.u_fgxm);
           mstform.getItem('user_fgzz').setValue(res.data.u_fgzz);
           mstform.getItem('user_fgdy').setValue(res.data.u_fgdy);
           var phid=res.data.u_cgpl;
           a1(phid);
           mstform.getItem('user_cgzygclb').setValue(phid); 
           mstform.getItem('PhidTenderCompany').setValue(res.data.ocode); 
           mstform.getItem('user_zbxm').setValue(res.data.pc); 
           mstform.getItem('user_bjfs').setValue(res.data.bjfs); 
   
   
           BatchBindCombox([mstform.getItem('PhidTenderType'),mstform.getItem('user_zbxm'),mstform.getItem('PhidTenderCompany'),mstform.getItem('user_gyslx'), mstform.getItem('user_cgfs'), mstform.getItem('user_ywlx_kj'), mstform.getItem('PhidTenderMethod'),mstform.getItem('user_fgxm'),mstform.getItem('user_fgzz'),mstform.getItem('user_fgdy')]);
  });
  
  
  //服务请购单
   var fwjh=mstform.getItem ('user_fwjh');                                 
   fwjh.on('beforetriggerclick', function (eOp, ignoreBeforeEvent) {
      fwjh.setClientSqlFilter('cgfs in (select phid from cg_mode  where phid in (964190416000001,964190416000006,100230105000003))')
  });
  fwjh.on('helpselected', function (res) {
           var a=res.data.phid;
           mstform.getItem('user_zbbh').setValue(res.data.bill_no);
           mstform.getItem('ProjectName').setValue(res.data.title);
           mstform.getItem('user_cgfs').setValue(res.data.cgfs);
           mstform.getItem('PhidTenderCompany').setValue(res.data.ocode);
           mstform.getItem('user_zbxm').setValue(res.data.xmid);
           execServer('getfwdz', {phid: a}, function (res1) {
                if (res1.data && res1.data.length > 0) {
                      var dz=res1.data[0].sf+res1.data[0].cs+res1.data[0].qx;//+res.data.dz
                      mstform.getItem('ProjectAddr').setValue(dz);
                }
           });
            mstform.getItem('user_gyslx').setValue(res.data.zygllx);
            mstform.getItem('PhidTenderType').setValue(res.data.zblx);
           mstform.getItem('user_cgzzms').setValue(res.data.cgzzms);
           mstform.getItem('user_cgkzj').setValue(res.data.amt);
           mstform.getItem('PhidTenderMethod').setValue(res.data.xyfs);
           mstform.getItem('user_fwywlx').setValue(res.data.ywlx);
           var phid=res.data.ywlx;
           a1(phid);
           mstform.getItem('user_cgzygclb').setValue(phid); 
           BatchBindCombox([mstform.getItem('user_gyslx'),mstform.getItem('PhidTenderType'),mstform.getItem('user_gyslx'), mstform.getItem('user_cgfs'), mstform.getItem('PhidTenderCompany'), mstform.getItem('PhidWinBidCompanys'),mstform.getItem('user_zbxm'),mstform.getItem('user_fwywlx'),mstform.getItem('PhidTenderMethod')]);
  });
  
//购置报告
 var gzbg=mstform.getItem ('user_gzbg');                                 
   gzbg.on('beforetriggerclick', function (eOp, ignoreBeforeEvent) {
      this.setClientSqlFilter('u_cgfs in (select phid from cg_mode  where phid in (964190416000001,964190416000006,100230105000003))')
  });
  gzbg.on('helpselected', function (res) {
           var a=res.data.phid;
           mstform.getItem('user_zbbh').setValue(res.data.bill_no);
           mstform.getItem('ProjectName').setValue(res.data.title);
           mstform.getItem('PhidTenderMethod').setValue(res.data.userhelp_2);
           mstform.getItem('PhidTenderCompany').setValue(res.data.ocode);
           mstform.getItem('user_zbxm').setValue(res.data.pc);
           //mstform.getItem('ProjectAddr').setValue(res.data.u_address);
           execServer('getzcdz', {phid: a}, function (res1) {
                if (res1.data && res1.data.length > 0) {
                      var dz=res1.data[0].sf+res1.data[0].cs+res1.data[0].qx;//+res.data.u_address
                      mstform.getItem('ProjectAddr').setValue(dz);
                      mstform.getItem('user_gyslx').setValue(res1.data[0].u_gyslx);
                      mstform.getItem('PhidTenderType').setValue(res1.data[0].u_zblx);
                }
           });
           mstform.getItem('user_cgkzj').setValue(res.data.amt);
           mstform.getItem('user_cgzzms').setValue(res.data.u_cgzzms);
           mstform.getItem('user_cgfs').setValue(res.data.u_cgfs);
           mstform.getItem('user_ywlx_zic').setValue(res.data.ywlxid);
           var phid=res.data.ywlxid;
           a1(phid);
           mstform.getItem('user_cgzygclb').setValue(phid); 
           BatchBindCombox([mstform.getItem('PhidTenderType'),mstform.getItem('user_gyslx'), mstform.getItem('user_cgfs'), mstform.getItem('PhidTenderCompany'), mstform.getItem('PhidTenderMethod'),mstform.getItem('user_zbxm'),mstform.getItem('user_ywlx_zic')]);
  });
  
    //采购计划
    mstform.getItem('user_zbsx').addListener('helpselected', function (res) {
        var phid = mstform.getItem('user_zbsx').getValue();
        execServer('mat_p_d_zbwj', {
            'mstphid': phid
        }, function (res) {
            if(!Ext.isEmpty(res)){
                for(var i = 0; i < res.data.length; i++){
                    Ext.Ajax.request({
                        async: false,
                        params: {
                            'asrsessionguid': '', //附件初始化Guid 可传空值，后台自动生成
                            'oritablename': 'mat_p_d_zbwj', //来源表
                            'oriasrattachtable': 'asr_info', //业务点对应的attachment_record表的asr_attach_table字段
                            'destasrattachtable': 'asr_info', //业务点对应的attachment_record表的asr_attach_table字段
                            'desttablename': 'pcm3_cnt_tenderproject_d_zbwj', //目的表
                            'destasrcode': guid(), //目的单据phid
                            'oriphid': res.data[i].lyphid //来源单据phid
                        },
                        url: C_ROOT + 'SUP/CustomCommon/CopyAttachment',
                        success: function (response) {
                            if (response.responseText == '0') {
                              //  Ext.Msg.alert('提示', '取数失败');
                                return;
                            } else {
                                mbusguid = response.responseText;
                                res.data[i].asr_session_guid = mbusguid;
                                res.data[i].DocAddr = mbusguid;
                            }
                        }
                    });
                }
                store.loadData(res.data);
            }
        });
      
        execServer('getMatPM', {
            phid: res.code
        }, function (res) {
            if (res.data && res.data.length > 0) {
                mstform.getItem('user_zbbh').setValue(res.data[0].bill_no);
                mstform.getItem('PhidTenderMethod').setValue(res.data[0].user_xyfs);
                mstform.getItem('ProjectName').setValue(res.data[0].user_title);


                //mstform.getItem('user_gyslx').setValue(res.data[0].user_gyslx);
       //getywlxbdw
                mstform.getItem('user_cgzzms').setValue(res.data[0].cgzzms);
                //mstform.getItem('user_ywlx_cl').setValue(res.data[0].user_ywlx_cl);
                mstform.getItem('user_ywlx_zy').setValue(res.data[0].user_ywlx_zy);
                //mstform.getItem('user_ywlx_sb').setValue(res.data[0].user_ywlx_sb);
                //mstform.getItem('user_ywlx_sz').userSetReadOnly(res.data[0].user_ywlx_sz);
                //mstform.getItem('user_ywlx_zc').userSetReadOnly(res.data[0].user_ywlx_zc);
                /*var a=res.data[0].user_gyslx;
                var phid=0;
                if(a=='1578'){
                   phid=res.data[0].user_ywlx_cl;
                   a1(phid);
                   mstform.getItem('user_cgzygclb').setValue(phid);
                }else if(a=='1580'){
                   phid=res.data[0].user_ywlx_sb;
                   a1(phid);
                   mstform.getItem('user_cgzygclb').setValue(phid);                             
                }else if(a=='1582'){
                    phid=res.data[0].user_ywlx_zc;
                    a1(phid);
                   mstform.getItem('user_cgzygclb').setValue(phid);                                   
                }else if(a=='100230329021002'){
                     phid=res.data[0].user_ywlx_sz;
                     a1(phid);
                     mstform.getItem('user_cgzygclb').setValue(phid);                              
                }*/
                mstform.getItem('user_cgfs').setValue(res.data[0].phid_cgtype);
                mstform.getItem('PhidTenderType').setValue(res.data[0].user_zygllx);
                //mstform.getItem('PhidPc').setValue('964200616000076');
                mstform.getItem('PhidTenderCompany').setValue(res.data[0].phid_ocode);
                var dz=res.data[0].sf+res.data[0].cs+res.data[0].qx;//+res.data[0].user_dhdz
                mstform.getItem('ProjectAddr').setValue(dz);
                projectAddr = res.data[0].user_dhdz;
                mstform.getItem('user_cgkzj').setValue(res.data[0].user_hskzzj);
                mstform.getItem('user_zbxm').setValue(res.data[0].phid_pc);

                //mstform.getItem('user_zbbh').userSetReadOnly(true);
                mstform.getItem('ProjectName').userSetReadOnly(true);
                mstform.getItem('user_gyslx').userSetReadOnly(true);
                mstform.getItem('user_ywlx_zy').userSetReadOnly(true);
                /*mstform.getItem('user_ywlx_cl').userSetReadOnly(true);
                mstform.getItem('user_ywlx_sb').userSetReadOnly(true);
                mstform.getItem('user_ywlx_sz').userSetReadOnly(true);
                mstform.getItem('user_ywlx_zc').userSetReadOnly(true);  */           
                mstform.getItem('user_cgfs').userSetReadOnly(true);
                //mstform.getItem('PhidPc').userSetReadOnly(true);
                mstform.getItem('PhidTenderCompany').userSetReadOnly(true);
                //mstform.getItem('ProjectAddr').userSetReadOnly(true);
                mstform.getItem('user_cgkzj').userSetReadOnly(true);
                mstform.getItem('user_zbxm').userSetReadOnly(true);
                //controlGridZlzqColumn(res.data[0].user_gyslx)
                controlGridJjgzColumn(res.data[0].phid_cgtype);
                controlFormYwlx(res.data[0].user_gyslx);
            } else {
                mstform.getItem('user_zbbh').setValue('');
                mstform.getItem('ProjectName').setValue('');
                mstform.getItem('user_gyslx').setValue('');
                mstform.getItem('user_cgfs').setValue('');
                mstform.getItem('PhidPc').setValue('');
                mstform.getItem('PhidTenderCompany').setValue('');
                mstform.getItem('user_ywlx_zy').setValue('');
                /*mstform.getItem('user_ywlx_cl').setValue('');
                mstform.getItem('user_ywlx_sb').setValue('');
                mstform.getItem('user_ywlx_zc').setValue('');
                mstform.getItem('user_ywlx_sz').setValue('');    */   
                mstform.getItem('ProjectAddr').setValue('');
                mstform.getItem('user_cgkzj').setValue('');
                mstform.getItem('user_zbxm').setValue('');
            }
            BatchBindCombox([mstform.getItem('PhidTenderType'),mstform.getItem('PhidTenderMethod'),mstform.getItem('user_gyslx'),mstform.getItem('user_cgfs'), mstform.getItem('PhidPc'), mstform.getItem('PhidTenderCompany'), mstform.getItem('user_ywlx_sb'), mstform.getItem('user_ywlx_zy'), mstform.getItem('user_ywlx_cl'), mstform.getItem('user_zbxm'), mstform.getItem('user_ywlx_zc'), mstform.getItem('user_ywlx_sz'), mstform.getItem('user_cgzygclb')]);
        })
    });
    mstform.getItem('user_ywlx_zy').addListener('beforetriggerclick', function(){
      this.setOutFilter({c_type: 'zyfb_ywlx'});
    })
  
  mstform.getItem('user_zyfbjh').addListener('beforetriggerclick', function(){
     this.setOutFilter({user_yybz: 0});
  })
  
    mstform.getItem('user_zyfbjh').addListener('helpselected', function (res) {
        var phid = mstform.getItem('user_zyfbjh').getValue();
        console.log(C_ROOT);
        execServer('pms3_fb_subj_d_zbwj1', {
            'mstphid': phid
        }, function (res) {
            if(!Ext.isEmpty(res)){
                for(var i = 0; i < res.data.length; i++){
                    Ext.Ajax.request({
                        async: false,
                        params: {
                            'asrsessionguid': '', //附件初始化Guid 可传空值，后台自动生成
                            'oritablename': 'pms3_fb_subj_d_zbwj', //来源表
                            'oriasrattachtable': 'asr_info', //业务点对应的attachment_record表的asr_attach_table字段
                            'destasrattachtable': 'asr_info', //业务点对应的attachment_record表的asr_attach_table字段
                            'desttablename': 'pcm3_cnt_tenderproject_d_zbwj', //目的表
                            'destasrcode': guid(), //目的单据phid
                            'oriphid': res.data[i].lyphid //来源单据phid
                        },
                        url: C_ROOT + 'SUP/CustomCommon/CopyAttachment',
                        success: function (response) {
                            if (response.responseText == '0') {
                                Ext.Msg.alert('提示', '取数失败');
                                return;
                            } else {
                                mbusguid = response.responseText;
                                res.data[i].asr_session_guid = mbusguid;
                                res.data[i].DocAddr = mbusguid;
                            }
                        }
                    });
                }
                store.loadData(res.data);
            }
        });

        var phid=res.code;
        execServer('getFbSubj', {
            phid: phid
        }, function (res) {
            if (res.data && res.data.length > 0) {
                mstform.getItem('user_zbbh').setValue(res.data[0].bill_no);
                mstform.getItem('ProjectName').setValue(res.data[0].bill_title);
                mstform.getItem('PhidTenderMethod').setValue(res.data[0].user_xyfs);
                mstform.getItem('user_cgzzms').setValue(res.data[0].user_cgzzms); 
                mstform.getItem('user_gyslx').setValue(res.data[0].user_gyslx);
                mstform.getItem('PhidTenderType').setValue(res.data[0].user_zblx);              
              
               /* var zygllx=res.data[0].user_gyslx;
                if(zygllx =='1579'){
                     var zy=res.data[0].user_ywlx;
                     a1(zy);
                     mstform.getItem('user_cgzygclb').setValue(zy);    
                }
                mstform.getItem('user_ywlx_zy').setValue(res.data[0].user_ywlx);
              */
              
                mstform.getItem('user_cgfs').setValue(res.data[0].user_cgfs);
                //mstform.getItem('PhidPc').setValue('964200616000076');
                mstform.getItem('PhidTenderCompany').setValue(res.data[0].phid_ocode);
                 execServer('getzydz', {phid: phid}, function (res1) {
                      if (res1.data && res1.data.length > 0) {
                            var dz=res1.data[0].sf+res1.data[0].cs+res1.data[0].qx;//+res.data[0].user_xmdz
                            mstform.getItem('ProjectAddr').setValue(dz);
                            projectAddr = dz;
                      }
                 });
                //mstform.getItem('ProjectAddr').setValue(res.data[0].user_xmdz);

                mstform.getItem('user_cgkzj').setValue(res.data[0].user_hskzzj);
                mstform.getItem('user_zbxm').setValue(res.data[0].phid_pc);
    
                //mstform.getItem('user_zbbh').userSetReadOnly(true);
                mstform.getItem('ProjectName').userSetReadOnly(true);
                mstform.getItem('user_gyslx').userSetReadOnly(true);
                //mstform.getItem('user_ywlx_cl').userSetReadOnly(true);
                //mstform.getItem('user_ywlx_zy').userSetReadOnly(true);
                /*mstform.getItem('user_ywlx_sb').userSetReadOnly(true);
                mstform.getItem('user_ywlx_sz').userSetReadOnly(true);
                mstform.getItem('user_ywlx_zc').userSetReadOnly(true);*/
                mstform.getItem('user_cgfs').userSetReadOnly(true);
                //mstform.getItem('PhidPc').userSetReadOnly(true);
                mstform.getItem('PhidTenderCompany').userSetReadOnly(true);
                mstform.getItem('ProjectAddr').userSetReadOnly(true);
                mstform.getItem('user_cgkzj').userSetReadOnly(true);
                mstform.getItem('user_zbxm').userSetReadOnly(true);
                //controlGridZlzqColumn(res.data[0].user_zygllx)
                controlGridJjgzColumn(res.data[0].phid_cgtype);
                controlFormYwlx(res.data[0].user_zygllx);
            } else {
                mstform.getItem('user_zbbh').setValue('');
                mstform.getItem('ProjectName').setValue('');
                //mstform.getItem('user_gyslx').setValue('');
                mstform.getItem('user_cgfs').setValue('');
                mstform.getItem('PhidPc').setValue('');
                mstform.getItem('PhidTenderCompany').setValue('');
                //mstform.getItem('user_ywlx_cl').setValue('');
                //mstform.getItem('user_ywlx_zy').setValue('');
                /*mstform.getItem('user_ywlx_sb').setValue('');
                mstform.getItem('user_ywlx_zc').setValue('');
                mstform.getItem('user_ywlx_sz').setValue('');  */            
                mstform.getItem('ProjectAddr').setValue('');
                mstform.getItem('user_cgkzj').setValue('');
                mstform.getItem('user_zbxm').setValue('');

            }
            BatchBindCombox([mstform.getItem('PhidTenderType'),mstform.getItem('user_gyslx'),mstform.getItem('user_cgzygclb'),mstform.getItem('PhidTenderMethod'),mstform.getItem('user_cgfs'), mstform.getItem('PhidPc'), mstform.getItem('PhidTenderCompany'), mstform.getItem('user_ywlx_sb'), mstform.getItem('user_ywlx_zy'), mstform.getItem('user_ywlx_cl'), mstform.getItem('user_zbxm'), mstform.getItem('user_ywlx_zc'), mstform.getItem('user_ywlx_sz')]);
        })
    });


    // --------------------------------新增招标文件tab页------------------------------------------

   var tabPanel = Ext.ComponentQuery.query('tabpanel')[0];

   //定义model
   var model =Ext.define('pcm3_cnt_tenderproject_d_zbwj', {
    extend: 'Ext.data.Model',
    fields: [
    {
        name: 'phid',
        type: 'string',
        mapping: 'phid'
    },{
        name: 'mstphid',
        type: 'string',
        mapping: 'mstphid'
    },{
        name: 'docName',
        type: 'string',
        mapping: 'docName'
    },{
        name: 'prepareName',
        type: 'bigint',
        mapping: 'prepareName'
    },{
        name: 'prepareName_name',
        type: 'string',
        mapping: 'prepareName_name'
    },{
        name: 'remarks',
        type: 'string',
        mapping: 'remarks'
    },{
        name: 'attach',
        type: 'string',
        mapping: 'attach'
    },{
        name: 'asr_session_guid',
        type: 'string',
        mapping: 'asr_session_guid'
    },{
        name: 'lyphid',
        type: 'string',
        mapping: 'lyphid'
    }
    ]
    });

    //定义store
    var store = Ext.create('Ext.ng.JsonStore', {
        model: model
    });

    //服务端取数后将数据load至store
  mstform.on('dataready', function () {
    if (otype != $Otype.ADD) {
        var mstphid = busid;
        execServer('pcm3_cnt_tenderproject_d_zbwj', {
            'mstphid': mstphid
        }, function (res) {
            if(!Ext.isEmpty(res)){
                store.loadData(res.data);
                for(i = 0; i < store.getCount(); i++) {
                    store.data.items[i].phantom = false;
                }
            }
        });
    }
  })

    //定义grid
    var grid = Ext.create('Ext.ng.GridPanel', {
        title: '招标文件',
        id: 'pcm3_cnt_tenderproject_d_zbwj',
        region: 'south',
        isInit: true,
        stateful: false,
        stateId: 'pcm3_cnt_tenderproject_d_zbwj',//所有单据不允许重复
        store: store,
        buskey: 'phid', //对应的业务表主键属性
        otype: otype,
        columnLines: true,
        tbar: [{
                xtype: 'button',
                itemId: 'addrow',
                text: '增行',
                iconCls: "icon-AddRow",
                handler: function () {
                    store.insert(store.getCount(), [{}]);
                }
            },
            {
                xtype: 'button',
                itemId: 'delrow',
                text: '删行',
                iconCls: "icon-DeleteRow",
                handler: function () {
                    var data = grid.getSelectionModel().getSelection();
                    Ext.Array.each(data, function (record) {
                        store.remove(record);
                    });
                }
            }
        ],
        columns: [Ext.create('Ext.grid.RowNumberer', {text: '序号' , width:45}),{
                header: Lang.pcm3_cnt_tenderproject_d_zbwj_phid||'主键',
                dataIndex: 'phid',
                itemId: 'phid',
                width: 100,
                sortable: true,
                hidden: true
            },{
                header: Lang.pcm3_cnt_tenderproject_d_zbwj_mstphid||'主表主键',
                dataIndex: 'mstphid',
                itemId: 'mstphid',
                width: 100,
                sortable: true,
                hidden: true
            },{
                header: Lang.pcm3_cnt_tenderproject_d_zbwj_docName||'文件名称',
                dataIndex: 'docName',
                itemId: 'docName',
                width: 150,
                sortable: true,
                mustInput:true,
                editor: {
                    xtype: 'ngText',
                    allowBlank: false
                }
            },{
                header: Lang.pcm3_cnt_tenderproject_d_zbwj_prepareName||'编制人代码',
                dataIndex: 'prepareName',
                itemId: 'prepareName',
                width: 100,
                sortable: true,
                hidden: true
            },{
                header: Lang.pcm3_cnt_tenderproject_d_zbwj_prepareName_name||'编制人',
                dataIndex: 'prepareName_name',
                itemId: 'prepareName_name',
                width: 100,
                sortable: true,
                editor: {
                    xtype: 'ngRichHelp',
                    valueField: 'phid',
                    displayField: 'cname',
                    listFields: 'phid,cname',
                    listHeadTexts: '编号,姓名',
                    helpid: 'eam3_hr_epm_main',
                    ORMMode: 'false',
                    allowBlank: true,
                    listeners: {
                        helpselected: function (obj) {
                            var data = grid.getSelectionModel().getSelection();
                            var rec = obj.data;
                            data[0].set('prepareName', rec.phid);
                            data[0].set('prepareName_name', rec.cname);
                        }
                    }
                }
            },{
                header: Lang.pcm3_cnt_tenderproject_d_zbwj_remarks||'备注',
                dataIndex: 'remarks',
                itemId: 'remarks',
                width: 200,
                sortable: true,
                editor: {
                    xtype: 'ngText',
                    allowBlank: true
                }
            },{
                header: Lang.pcm3_cnt_tenderproject_d_zbwj_attach||'附件',
                dataIndex: 'attach',
                itemId: 'attach',
                width: 100,
                sortable: true,
            },{
                header: Lang.pcm3_cnt_tenderproject_d_zbwj_asr_session_guid||'附件id',
                dataIndex: 'asr_session_guid',
                itemId: 'asr_session_guid',
                width: 100,
                sortable: true,
                hidden: true
            },{
                header: Lang.pcm3_cnt_tenderproject_d_zbwj_lyphid||'来源phid',
                dataIndex: 'lyphid',
                itemId: 'lyphid',
                width: 100,
                sortable: true,
                hidden: true
            }
            ],
            plugins: [
                Ext.create('Ext.grid.plugin.CellEditing', {
                    clicksToEdit: 1
                })
            ]
        }); 
    
    tabPanel.add(grid);


    grid.getColumn('attach').renderer = function(val) {
        return '<div style="flex:1;text-align:center"><span role="img"  class="x - btn - icon - el iconfont iconattach " unselectable="on">&nbsp;</span></div>'
    };
    grid.getColumn('attach').on('dblclick', function(e, opt) {
        gridclickFlag = true;
        var griddata = grid.getSelectionModel().getSelection();
        var buscode;
        var busguid;
        if (griddata.length <= 0) {
            return;
        } else {
            buscode = griddata[0].get('phid');
            busguid = griddata[0].get('asr_session_guid');
        }

        var param = {
            product: "",
            attachguid: busguid,
            attachTName: "asr_info",
            busTName: 'pcm3_cnt_tenderproject_d_zbwj',
            busid: buscode,
            orgid: $appinfo.orgID
        };
        var result = LoadAttach.InitBeforeOpen(param);
        var obj = eval(result);
        if (obj) {
            if (obj.status == "success") //初始化成功
            {
                busguid = obj.msg;
            } else {
                Ext.MessageBox.alert('提示', "附件初始化失败");
                return;
            }
        } else {
            Ext.MessageBox.alert('提示', "附件初始化失败");
            return;
        }
        griddata[0].set('DocAddr', busguid);
        griddata[0].set('asr_session_guid', busguid);
        var opt = {
            product: "", //传相应产品，可为空
            mode: "NG3", //固定传NG3
            openbymianframe: "1", //通过主框架打开附件 0或空否  1 是固定传1
            oper: "winfrom", //web、pb、winfrom、progress（进度条模式）,固定传 winfrom
            asr_tbl: "asr_info",
            tbl: "pcm3_cnt_tenderproject_d_zbwj", //传相应业务表
            fill: $appinfo.logid, //传相应操作员id
            fillname: $appinfo.username, //传相应操作员姓名
            chkSign: "0", //默认传0
            chkCheckIn: "0", //默认传0
            btnAdd: "1", //新增按钮oper非web时有效 0、禁用 1、显示 2、隐藏
            addserverstuts: "0", //导入按钮oper非web时有效 0、禁用 1、显示 2、隐藏
            btnScan: "1", //扫描按钮oper非web时有效 0、禁用 1、显示 2、隐藏
            btnDelete: "1", //删除按钮oper非web时有效 0、禁用 1、显示 2、隐藏
            btnEdit: "1", //编辑按钮oper非web时有效 0、禁用 1、显示 2、隐藏
            btnView: "1", //查看按钮oper非web时有效 0、禁用 1、显示 2、隐藏
            btnDownload: "1", //下载按钮oper非web时有效 0、禁用 1、显示 2、隐藏
            btnCancel: "1", //取消按钮oper非web时有效 0、禁用 1、显示 2、隐藏
            btnOk: "1", //确定按钮oper非web时有效 0、禁用 1、显示 2、隐藏
            btnWebAdd: "2", //web新增按钮oper为web时有效 0、禁用 1、显示 2、隐藏
            btnWebOk: "2", //web新增按钮oper为web时有效 0、禁用 1、显示 2、隐藏
            archivestuts: "2", //归档按钮oper非web时有效 0、禁用 1、显示 2、隐藏
            status: otype, //add 新增模式，view 查看模式， edit 编辑模式
            showlist: "1", //显示文件列表 0 不显示 1显示
            zip: "0", //附件压缩 0 不压缩 1 压缩
            filenum: 1, //附件上传数量限制 0或空不限制附件上传数量
            filetype: "", //附件上传类型限制目前仅支持传入"image",如果传了"image"附件控件就只能上传图片
            guid: busguid //传第二步附件初始化获得的guid
        };
        LoadAttach.Init(opt);
    });    

}


function getExtendData() {
	//后端自动生成phid
	var grid = Ext.getCmp('pcm3_cnt_tenderproject_d_zbwj');
	var store = grid.store;
	var extendObj = {
		tablename: 'pcm3_cnt_tenderproject_d_zbwj',
		data: grid.getChange(false)
	};
	return {
		'pcm3_cnt_tenderproject_d_zbwj': JSON.stringify(extendObj)
	};
}

function AttachReturnValue(key, value) {
    var dgrid = Ext.getCmp('pcm3_cnt_tenderproject_d_zbwj');
    switch (key) {
        case "closeNG3Container": //附件控件窗口关闭事件
            var attName = "";
            var attCou = 0;
            var attInf = eval(value);
            if (attInf && attInf.length > 0) {
                for (var i = 0; i < attInf.length; i++) {
                    if (i == (attInf.length - 1)) {
                        attName = attName + attInf[i].asr_name.split(".")[0]; //主键: asr_fid，名称asr_name，大小: asr_size，上传人: asr_fillname，上传日期: asr_filldt
                    } else {
                        attName = attName + attInf[i].asr_name + ",";
                    }
                }
            }
            attCou = attInf.length;

            if (gridclickFlag) {
                var griddata = dgrid.getSelectionModel().getSelection();
                var docName = griddata[0].get('docName');
                if (!docName)
                    griddata[0].set('docName', attName);
            } else {
                isAttach = attInf.length > 0 ? "1" : "0";
            }
        
       		 ///附件后台保存
            var attachinfo = eval(value); //附件窗口关闭后返回附件列表信息，可回填单据页面附件信息
            //add by zjw 2021-6-16
            attachinfos = attachinfo;

            var result = LoadAttach.Save("", attachinfo.asr_fid, '');
            var obj = eval(result);
        break;
    }
}


//保存后回调方法
function afterSaveForSecDev(resp){
    var mstform = Ext.getCmp('tenderprojectMst_form');
    var cgjh = mstform.getItem('user_zbsx').getValue();
    var zyfbcgjh = mstform.getItem('user_zyfbjh').getValue();
    var phid = resp.KeyCodes[0];
    execServer('pcm3_cnt_tenderproject_d_zbwj', {
        'mstphid': phid
    }, function (res) {
        if(!Ext.isEmpty(res) && res.data[0]){
            for( var i = 0; i < res.count; i++) {
                if(Ext.isEmpty(res.data[i].lyphid) || res.data[i].lyphid == '0'){//来源phid为空，保存附件信息,否则拷贝
                    LoadAttach.Save("", res.data[i].asr_session_guid , res.data[i].phid );
                }else{
                    if(!Ext.isEmpty(cgjh)){
                        Ext.Ajax.request({
                            async: false,
                            params: {
                                'asrsessionguid': '', //附件初始化Guid 可传空值，后台自动生成
                                'oritablename': 'mat_p_d_zbwj', //来源表
                                'oriasrattachtable': 'asr_info', //业务点对应的attachment_record表的asr_attach_table字段
                                'destasrattachtable': 'asr_info',
                                'desttablename': 'pcm3_cnt_tenderproject_d_zbwj', //目的表
                                'destasrcode': res.data[i].phid, //目的单据phid
                                'oriphid': res.data[i].lyphid //来源单据phid
                            },
                            url: C_ROOT + '{}}',
                            success: function (response) {
                                if (response.responseText == '0') {
                                    Ext.Msg.alert('提示', '取数失败');
                                    return;
                                } else {
                                    mbusguid = response.responseText;
                                  LoadAttach.Save("", mbusguid , res.data[i].phid );
                                  execServer('pcm3_cnt_tenderproject_d_zbwj_update', {
                                        'guid': mbusguid,
                                        'phid': res.data[i].phid
                                    }, function (res) {
                                        if(!Ext.isEmpty(res) && res.data[0]){
                                        }
                                    })
                                }
                            }
                        });
                    }else if(!Ext.isEmpty(zyfbcgjh)){
                        Ext.Ajax.request({
                            async: false,
                            params: {
                                'asrsessionguid': '', //附件初始化Guid 可传空值，后台自动生成
                                'oritablename': 'pms3_fb_subj_d_zbwj', //来源表
                                'oriasrattachtable': 'asr_info', //业务点对应的attachment_record表的asr_attach_table字段
                                'destasrattachtable': 'asr_info',
                                'desttablename': 'pcm3_cnt_tenderproject_d_zbwj', //目的表
                                'destasrcode': res.data[i].phid, //目的单据phid
                                'oriphid': res.data[i].lyphid //来源单据phid
                            },
                            url: C_ROOT + 'SUP/CustomCommon/CopyAttachment',
                            success: function (response) {
                                if (response.responseText == '0') {
                                    Ext.Msg.alert('提示', '取数失败');
                                    return;
                                } else {
                                    mbusguid = response.responseText;
                                  LoadAttach.Save("", mbusguid , res.data[i].phid );
                                  execServer('pcm3_cnt_tenderproject_d_zbwj_update', {
                                        'guid': mbusguid,
                                        'phid': res.data[i].phid
                                    }, function (res) {
                                        if(!Ext.isEmpty(res) && res.data[0]){
                                        }
                                    })
                                }
                            }
                        });
                    }
                }
            }
        }
    });
}


function guid() {
    function S4() {
        return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
    }
    return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
